﻿using IQIGame.Onigao.Framework.Serialization;

namespace IQIGame.Onigao.Logic
{
    public static class StoryFactory
    {
        public static StoryConfig Create(byte[] bytes)
        {
            var rByteBuf = ThreadLocalTemporalByteBufPool.Alloc(bytes.Length);
            rByteBuf.Replace(bytes);
            var rConfig =　rByteBuf.DeSerializeObject<StoryConfig>();
            ThreadLocalTemporalByteBufPool.Free(rByteBuf);
            return rConfig;
        }

        public static SerializeCustomConfig CreateNodeConfig(this EStoryNodeType type)
        {
            switch (type)
            {
                case EStoryNodeType.Normal:
                    return new StoryNode_Normal();
                case EStoryNodeType.Option:
                    return new StoryNode_Option();
                case EStoryNodeType.End:
                    return new StoryNode_End();
                case EStoryNodeType.Timeline:
                    return new StoryNode_Timeline();
                case EStoryNodeType.RemoveSpeaker:
                    return new StoryNode_Remove3DNpc();
                case EStoryNodeType.Effect:
                    return new StoryNode_Effect();
                case EStoryNodeType.CenterContents:
                    return new StoryNode_CenterContents();
                case EStoryNodeType.Speaker:
                    return new StoryNode_Speaker();
                case EStoryNodeType.Bgm:
                    return new StoryNode_Bgm();
                case EStoryNodeType.Video:
                    return new StoryNode_Video();
                case EStoryNodeType.BackgroundAction:
                    return new StoryNode_BackgroundAction();
            }
            return null;
        }
    }
}